# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=bash-completion
pkgver=2.1
pkgrel=6
pkgdesc="Programmable completion for the bash shell"
arch=('any')
url="http://bash-completion.alioth.debian.org/"
license=('GPL')
groups=('base')
depends=('bash')
options=('!emptydirs' '!makeflags')
source=(http://bash-completion.alioth.debian.org/files/${pkgname}-${pkgver}.tar.bz2
        words_bad_array_subscript.patch
        quote_readline_by_ref_fixes.patch)
md5sums=('4e2a9f11a4042a38ee79ddcd048e8b9e'
         'f524a2d082fe5f799ab262c91a0cd507'
         'fddc94f7c6bfe6d011d923ff62d4d839')
prepare() {
  cd ${pkgname}-${pkgver}
  patch -p1 -i ${srcdir}/words_bad_array_subscript.patch
  patch -p1 -i ${srcdir}/quote_readline_by_ref_fixes.patch

  autoreconf --install
}

build() {
  cd ${pkgname}-${pkgver}
  ./configure --prefix=/usr --sysconfdir=/etc
  make
}

package() {
  cd ${pkgname}-${pkgver}
  make DESTDIR="${pkgdir}" install

  mkdir -p ${pkgdir}/usr/lib
  mv -f ${pkgdir}/usr/share/pkgconfig ${pkgdir}/usr/lib/
  # bash-completion is sourced in /etc/bash.bashrc so that non-bash shell don't source it
  #  rm "${pkgdir}/etc/profile.d/bash_completion.sh"

  rm "${pkgdir}"/usr/share/bash-completion/completions/{cal,makepkg,hexdump,look,renice}
}
